<?php
namespace app\common\service\store;



use app\admin\model\store\Goods;
use app\admin\model\store\Recommend;
use app\common\service\BaseService;

class RecommendService extends BaseService
{
    /**
     * Author:Yingbo Sun
     * 获取快捷入口配置
     * @return array
     */
    public static function getCommend()
    {
        $data = Recommend::field(['id','title','label'])->select();
        $data && $data = $data->toArray();

        if ($data){
            return self::success('获取成功',$data);
        }

        return self::fail('数据为空');
    }

    /**
     * 模块化查询商品
     * @param $label
     * @return Goods
     */
    public static function getCommendGoods($label)
    {
        try {
            $data = Goods::where($label,'1')
                ->order('create_time','desc')
                ->limit(config('setting.limit'))
                ->field(['id','goods_name','image','goods_price','original_price'])
                ->select();
        }catch (\Exception $e){
            return $res = [
                'code' => 400,
                'message' => '参数错误',
                'data' => []
            ];
        }
        if ($data){
            $res = [
                'code' => 200,
                'message' => '获取成功',
                'data' => $data
            ];
        }else{
            $res = [
                'code' => 400,
                'message' => '数据为空',
                'data' => []
            ];
        }
        return $res;
    }

}